/**
 * Created by dale on 2017/10/26.
 */
$(document).ready(function () {

    myPage.init({page:1,rows:20});
    myPage.ajax('mobile/shortcut/getTrackTask/'+type,{},function (data) {
        myPage.setTotal(data['total']);
        var str='';
        var width = $(window).width()-170;
        $.each(data['rows'],function (i,item) {
            str+='<li><a href="javascript:void(0)" nodeId="'+item['iTTId']+'" onclick="openit(this)"><div class="content" style="width: '+width+'px;" >'+item['sTaskName']+'</div><div class="m-right" ><span  class="m-badge c1">'+item['iState']+'</span></div></a></li>';
        });
        if(data['rows'].length>0) {
            $('#list').append(str);
        }
    });

    $('#prePage').bind('click',function () {
       var res =  myPage.beforePage();
       if(res){
           myPage.ajax('mobile/shortcut/getTrackTask/'+type,{},function (data) {
               myPage.setTotal(data['total']);

               var str='';
               var width = $(window).width()-170;

               $.each(data['rows'],function (i,item) {
                   str+='<li><a href="javascript:void(0)" nodeId="'+item['iTTId']+'" onclick="openit(this)"><div class="content" style="width: '+width+'px;" >'+item['sTaskName']+'</div><div class="m-right" ><span  class="m-badge c1">'+item['iState']+'</span></div></a></li>';
               });
               if(data['rows'].length>0) {
                   $('#list').empty();
                   $('#list').append(str);
               }
           });
       }
    });

    $('#nextPage').bind('click',function () {
        var res =myPage.nextPage();
        console.log(res);
        if(res){
            myPage.ajax('mobile/shortcut/getTrackTask/'+type,{},function (data) {
                myPage.setTotal(data['total']);
                var str='';
                var width = $(window).width()-170;
                $.each(data['rows'],function (i,item) {
                    str+='<li><a href="javascript:void(0)" nodeId="'+item['iTTId']+'" onclick="openit(this)"><div class="content" style="width: '+width+'px;" >'+item['sTaskName']+'</div><div class="m-right" ><span  class="m-badge c1">'+item['iState']+'</span></div></a></li>';
                });
                if(data['rows'].length>0) {
                    $('#list').empty();
                    $('#list').append(str);
                }
            });
        }
    });




    window.top.bindBack(function () { //返回
        window.top.goHome();
    });

});
function openit(target){
    window.top.registerBack();//注册返回
    var id   = $(target).attr('nodeId');
    var title = $(target).find('.content').text();
    $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/shortcut/taskDetail/'+id);
    window.parent.setTitle(title);
    window.parent.goTarget();
}